<template>
  <div class="container">
    <headerBar
      :title="titleBar == false ? local.WarehouseEntryToBeSubmitted : local.warehouseEntrySubmitted"
      @changeLan="changeLan"
      @pageReturn="pageReturn"
    ></headerBar>
    <div class="all" :style="{paddingTop: pdt+'px'}">
      <div class="top">
        <div class="select-panel">
          <div class="record-Number">
            <div class="a">{{local.stockInNo}}：{{objEdit.code}}</div>
            <div class="b">{{objEdit.createTime}}</div>
          </div>
          <div class="panel-supplier">
            <div class="name">
              <span style="color: red;">*</span>
              {{local.supplier}}：
            </div>
            <div class="page" style="border-bottom: 2rpx solid;">
              <picker
                class="weui-btn"
                @change="PickerChange"
                :range="array"
                :disabled="objEdit.status != 'PASS'? false: true"
                :index="indexPicker"
                :range-key="'supplierName'"
              >
                <input
                  type="default"
                  disabled
                  v-model="objEdit.supplierName"
                  :placeholder="local.option"
                />
                <span class="unit">▼</span>
              </picker>
            </div>
          </div>
          <div class="panel-supplier">
            <div class="name">
              <span style="color: red;">*</span>
              {{local.buyArea}}
            </div>
            <div class="page" style="border-bottom: 2rpx solid;">
              <picker
                class="weui-btn"
                @change="changeBuyArea"
                :range="buyAreaList"
                :value="buyAreaPickerIndex"
                range-key="buyAreaName"
              >
                <input
                  type="default"
                  v-model="objEdit.buyAreaName"
                  disabled
                  :placeholder="local.peleaseEnter"
                />
                <span class="unit">▼</span>
              </picker>
            </div>
          </div>
          <div class="panel-ware">
            <div class="name">
              <span style="color: red;">*</span>
              {{local.warehouseIn}}：
            </div>
            <div class="page" style="border-bottom: 2rpx solid;">
              <picker
                class="weui-btn"
                @change="PickerWarehouseChange"
                :index="indexWarePicker"
                :disabled="objEdit.status != 'PASS'? false: true"
                :range="arrayWarehouse"
                :range-key="'warehouseName'"
              >
                <input
                  type="default"
                  v-model="objEdit.warehouseName"
                  disabled
                  :placeholder="local.option"
                />
                <span class="unit">▼</span>
              </picker>
            </div>
          </div>
          <div class="panel-goods">
            <div class="name">{{local.goodsName}}：</div>
            <div class="names-goods">{{objEdit.goodsName}}</div>
          </div>
        </div>
      </div>
      <div class="select-photo">
        <div class="a name">
          <span style="color: red;">*</span>
          {{local.photosBeforeAcceptance}}
        </div>
        <div class="b">
          <div class="page">
            <div class="weui-uploader__bd">
              <div class="weui-uploader__files" id="uploaderFiles">
                <block v-for="(item, index) in filesStart" :key="index">
                  <div class="weui-uploader__file">
                    <img
                      class="weui-uploader__img"
                      :src="Shop+item"
                      mode="aspectFill"
                      :id="item"
                      @click="predivImage"
                      :data-urls="filesStart"
                    />
                    <div
                      v-if="objEdit.status != 'PASS'? true: false"
                      style="color: #DE6E7C;display: flex;justify-content: center;font-size: 26rpx;"
                      @click="deleteImgStart(item)"
                    >{{local.deletesingle}}</div>
                  </div>
                </block>
              </div>
              <div class="weui-uploader__input-box" v-if="objEdit.status != 'PASS'? true: false">
                <div class="weui-uploader__input" @click="chooseImage"></div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="stock-detail-panel">
        <div class="stock-detail-belt">
          <span class="name">
            <span style="color: red;width: 2rpx;">*</span>
            {{local.beltType}}：
          </span>
          <div class style="border-bottom: 2rpx solid;">
            <picker
              class="weui-btn"
              mode="selector"
              @change="PickerBeltChange"
              :disabled="objEdit.status != 'PASS'? false: true"
              :value="indexBeltPicker"
              :range="arrayBelt"
              :range-key="'dictLabel'"
            >
              <input type="default" v-model="beltType" disabled :placeholder="local.option" />
              <span class="unit">▼</span>
            </picker>
          </div>
        </div>
        <div class="msg-detail-thickness" v-if="objEdit.beltType=='4'||beltTypeNameInputFlag">
          <span class="name">
            <span style="color: red;width: 2rpx;">*</span>
            {{local.beltTypeName}}：
          </span>
          <div class style="border-bottom: 2rpx solid;">
            <input
              v-model="objEdit.beltTypeName"
              :disabled="objEdit.status != 'PASS'? false: true"
              @input="changeBeltTypeNameInput"
              :placeholder="local.peleaseEnter"
            />
          </div>
        </div>
        <div class="msg-detail-grade">
          <span class="name">
            <span style="color: red;width: 2rpx;">*</span>
            {{local.grade}}：
          </span>
          <div class style="border-bottom: 2rpx solid;">
            <picker
              class="weui-btn"
              @change="PickerLevelChange"
              :value="indexLevelPicker"
              :disabled="objEdit.status != 'PASS'? false: true"
              :range="arrayLevel"
              :range-key="'dictLabel'"
            >
              <input type="default" v-model="goodsLevel" disabled :placeholder="local.option" />
              <span class="unit">▼</span>
            </picker>
          </div>
        </div>
        <div class="msg-detail-thickness">
          <span class="name">
            <span style="color: red;width: 2rpx;">*</span>
            {{local.thickness}}：
          </span>
          <div class style="border-bottom: 2rpx solid;">
            <input
              type="digit"
              v-model="objEdit.sizeHeight"
              :disabled="objEdit.status != 'PASS'? false: true"
              :placeholder="local.peleaseEnter"
            />
            <span class="unit">MM</span>
          </div>
        </div>
        <div class="msg-detail-width">
          <span class="name">
            <span style="color: red;width: 2rpx;">*</span>
            {{local.width}}：
          </span>
          <div class style="border-bottom: 2rpx solid;">
            <input
              type="digit"
              v-model="objEdit.sizeWidth"
              :disabled="objEdit.status != 'PASS'? false: true"
              :placeholder="local.peleaseEnter"
            />
            <span class="unit">MM</span>
          </div>
        </div>
        <div class="msg-detail-long">
          <span class="name">
            <span style="color: red;width: 2rpx;">*</span>
            {{local.length}}：
          </span>
          <div class style="border-bottom: 2rpx solid;">
            <input
              type="digit"
              v-model="objEdit.sizeLong"
              :disabled="objEdit.status != 'PASS'? false: true"
              :placeholder="local.peleaseEnter"
            />
            <span class="unit" style="right: 16%;text-align: left;width: 5%;">M</span>
            <picker
              style="width: 10%;font-size: 38rpx;"
              :disabled="objEdit.status != 'PASS'? false: true"
              class="weui-btn"
              @change="PickerSymbolChange"
              :value="indexSymbolPicker"
              :range="arraySymbol"
            >
              <input type="default" v-model="objEdit.semiology" disabled />
            </picker>
          </div>
        </div>
        <div class="msg-detail-long">
          <span class="name">
            <span style="color: red;width: 2rpx;">*</span>
            {{local.weight}}：
          </span>
          <div class style="border-bottom: 2rpx solid;">
            <input
              type="digit"
              v-model="objEdit.weight"
              :disabled="objEdit.status != 'PASS'? false: true"
              :placeholder="local.peleaseEnter"
            />
            <span class="unit">T</span>
          </div>
        </div>
        <div class="msg-detail-grade">
          <span class="name">{{local.frameType}}：</span>
          <div class style="border-bottom: 2rpx solid;">
            <picker
              class="weui-btn"
              @change="PickerFrameTypeChange"
              :value="indexFrameTypePicker"
              :range="arrayFrameType"
              :range-key="'dictLabel'"
            >
              <input type="default" disabled v-model="frameTypeText" :placeholder="local.option" />
              <span class="unit">▼</span>
            </picker>
          </div>
        </div>
        <div class="msg-detail-grade" v-if="indexFrameTypePicker == 0">
          <span class="name">{{local.hub}}：</span>
          <div class style="border-bottom: 2rpx solid;">
            <picker
              class="weui-btn"
              :disabled="objEdit.status != 'PASS'? false: true"
              @change="PickerHubChange"
              :value="indexHubPicker"
              :range="arrayHub"
              :range-key="'dictLabel'"
            >
              <input type="default" v-model="hubText" disabled :placeholder="local.option" />
              <span class="unit">▼</span>
            </picker>
          </div>
        </div>
        <!-- hub选择其他（indexHubPicker=2），则出现hub 备注-->
        <div class="msg-detail-long" v-if="indexHubPicker == 2">
          <span class="name">{{local.hubName}}：</span>
          <div class style="border-bottom: 2rpx solid;">
            <input
              type="text"
              v-model="objEdit.hubName"
              :placeholder="local.peleaseEnter"
              :disabled="objEdit.status != 'PASS'? false: true"
            />
          </div>
        </div>
        <div class="msg-detail-grade" v-if="indexFrameTypePicker == 1">
          <span class="name">{{local.steelReel}}：</span>
          <div class style="border-bottom: 2rpx solid;">
            <picker
              class="weui-btn"
              :disabled="objEdit.status != 'PASS'? false: true"
              @change="PickerSteelReelChange"
              :value="indexSteelReelPicker"
              :range="arraySteelReel"
              :range-key="'dictLabel'"
            >
              <input type="default" v-model="steelReelText" disabled :placeholder="local.option" />
              <span class="unit">▼</span>
            </picker>
          </div>
        </div>
        <!-- steelReel选择其他（indexSteelReelPicker=4），则出现hub 备注-->
        <div class="msg-detail-long" v-if="indexSteelReelPicker == 4">
          <span class="name">{{local.steelReelName}}：</span>
          <div class style="border-bottom: 2rpx solid;">
            <input
              type="text"
              v-model="objEdit.steelReelName"
              :placeholder="local.peleaseEnter"
              :disabled="objEdit.status != 'PASS'? false: true"
            />
          </div>
        </div>
      </div>
      <div class="select-photo">
        <div class="a name">
          <span style="color: red;width: 2rpx;">*</span>
          {{local.photosAfterAcceptance}}
        </div>
        <div class="b">
          <div class="page">
            <div class="weui-uploader__bd">
              <div class="weui-uploader__files" id="uploaderFiles">
                <block v-for="(item, index) in filesEnd" :key="index">
                  <div class="weui-uploader__file">
                    <img
                      class="weui-uploader__img"
                      :src="Shop+item"
                      mode="aspectFill"
                      :id="item"
                      @click="predivImageEnd"
                      :data-urls="filesEnd"
                    />
                    <div
                      v-if="objEdit.status != 'PASS'? true: false"
                      style="color: #DE6E7C;display: flex;justify-content: center;font-size: 26rpx;"
                      @click="deleteImgEnd(item)"
                    >{{local.deletesingle}}</div>
                  </div>
                </block>
              </div>
              <div class="weui-uploader__input-box" v-if="objEdit.status != 'PASS'? true: false">
                <div class="weui-uploader__input" @click="chooseImageEnd"></div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="stock-detail-panel">
        <div class="msg-detail-long">
          <span
            class="name"
            :class="lang == 'zh'||lang =='zh_CN'?'w_100':'w_160'"
          >{{local.weighbridgeTerminalNo}}：</span>
          <div class style="border-bottom: 2rpx solid;width: auto;flex: 1;">
            <input
              :disabled="objEdit.status != 'PASS'? false: true"
              v-model="objEdit.weightBridgePier"
              :placeholder="local.peleaseEnter"
            />
          </div>
        </div>
        <div class="msg-detail-long">
          <span
            class="name"
            :class="lang == 'zh'||lang =='zh_CN'?'w_100':'w_160'"
          >{{local.supplierInvoiceNumber}}：</span>
          <div class style="border-bottom: 2rpx solid;width: auto;flex: 1;">
            <input
              :disabled="objEdit.status != 'PASS'? false: true"
              v-model="objEdit.supplierInvoice"
              :placeholder="local.peleaseEnter"
            />
          </div>
        </div>
        <div class="msg-detail-long">
          <div class="name jt_flex_row_right" style="width:190rpx">{{local.invoiceDate}}：</div>
          <!--            <div class="names-goods">{{saveObj.invoiceDate}}</div>-->
          <picker
            class="weui-btn"
            style="flex: 1;"
            mode="date"
            :value="objEdit.invoiceDate"
            start="1999-01-01"
            end="2099-01-01"
            :disabled="objEdit.status != 'PASS'? false: true"
            @change="TimeChange"
          >
            <input
              style="border-bottom: 2rpx solid;width: auto;flex: 1;"
              v-model="invoiceDateFormat"
              :placeholder="local.peleaseEnter"
              disabled
            />
          </picker>
        </div>
      </div>
      <div class="remark">
        <div>{{local.remark1}}:</div>
        <textarea
          v-model="objEdit.remark"
          :disabled="objEdit.status != 'PASS'? false: true"
          style="height: 100rpx;max-width: 879rpx;resize: none;padding-left: 18rpx;"
        ></textarea>
      </div>
      <div class="remark">
        <div>{{local.remark2}}:</div>
        <textarea
          v-model="objEdit.remark2"
          :disabled="objEdit.status != 'PASS'? false: true"
          style="height: 100rpx;max-width: 879rpx;resize: none;padding-left: 18rpx;"
        ></textarea>
      </div>
    </div>
    <div class="bottom-bar" v-if="objEdit.status!='PASS'?true:false">
      <!--        <div class="save-draft" @click="editBtnAgain">{{local.submitAndContinueToCreateNewWarehouseEntry}}</div>-->
      <!-- 不允许修改 -->
      <button class="confirm" style="font-size: 26rpx;" @click="editBtn">{{local.submit}}</button>
    </div>
  </div>
</template>

<script>
import home from "@/api/home"
import headerBar from "@/components/headerBar"
import Shop from "../../../../config/shop"
import { throttle } from "@/utils/throttle"
import { previewImage, dictMatching } from "@/utils/index"
export default {
  components: {
    headerBar,
  },
  onShow() {
    this.initLang()
    this.initData()
    // this.getBelt()
    // this.getLevel()
    // this.getDict('hubType')
    // this.getDict('steelReel')
    this.getWarehouseList()
  },
  pageReturn() {},
  onLoad(options) {
    this.initLang()
    if (options.id) {
      //从草稿箱来
      this.id = options.id
      this.getInStockListId()
    }
    this.pdt = this.globalData.CustomBar
  },

  computed: {
    invoiceDateFormat(){
      const {invoiceDate} = this.objEdit
      return invoiceDate ? wx.$timeFormat(invoiceDate) : '' //new Date(invoiceDate).$format('dd/MM/yyyy') :''    
    },
  },
  methods: {
    TimeChange (e) {
      this.objEdit.invoiceDate = e.mp.detail.value
    },
    changeBeltTypeNameInput (e) {
      this.objEdit.beltTypeName = e.mp.detail.value
      // this.saveObj.beltTypeName = e.mp.detail.value
    },
    initLang(){
      this.local = wx.getStorageSync('local')
      this.lang = wx.getStorageSync('lang')
    },
    // async getDict (type) {
    //   const {rows} = await home.getBeltLevel({dictType: type})
    //   switch(type){
    //     case 'hubType':
    //       this.arrayHub = rows
    //       this.objEdit.hub = this.arrayHub[0].dictValue
    //       break
    //     case 'steelReel':
    //       this.arraySteelReel = rows
    //       this.objEdit.steelReel = this.arraySteelReel[0].dictValue
    //       break
    //   }
    // },
    deleteImgStart(ite) {
      this.filesStart = this.filesStart.filter(item => item !== ite)
    },
    deleteImgEnd(ite) {
      this.filesEnd = this.filesEnd.filter(item => item !== ite)
    },
    initData() {
      this.array = wx.getStorageSync("supplierArray") || []
      this.buyAreaList = wx.getStorageSync('buyAreaList') || []
    },
    async getGoodsName(supplierName) {
      const data = await home.getGoodsName({ supplierName: supplierName })
      this.objEdit.goodsName = data.msg
    },
    PickerFrameTypeChange(e){
      this.indexFrameTypePicker = e.mp.detail.value
      this.frameTypeText = this.arrayFrameType[e.mp.detail.value].dictLabel
      this.objEdit.frameType = this.arrayFrameType[e.mp.detail.value].dictValue
      //切换框架类型时，清空 hub/轮轴
      this.indexHubPicker = null
      this.indexSteelReelPicker = null
      this.hubText = ''
      this.steelReelText = ''
      this.objEdit.hub = ''
      this.objEdit.hubName = ''
      this.objEdit.steelReelName = ''
      this.objEdit.steelReel = ''
      this.saveObj.hub = ''
      this.saveObj.hubName = ''
      this.saveObj.steelReelName = ''
      this.saveObj.steelReel = ''
    },
    PickerHubChange(e){
      this.indexHubPicker = e.mp.detail.value
      this.hubText = this.arrayHub[e.mp.detail.value].dictLabel
      this.objEdit.hub = this.arrayHub[e.mp.detail.value].dictValue
    },
    PickerSteelReelChange(e){
      this.indexSteelReelPicker = e.mp.detail.value
      this.steelReelText = this.arraySteelReel[e.mp.detail.value].dictLabel
      this.objEdit.steelReel = this.arraySteelReel[e.mp.detail.value].dictValue
    },
    PickerSymbolChange (e) {
      this.indexSymbolPicker = e.mp.detail.value
      this.objEdit.semiology = this.arraySymbol[e.mp.detail.value]
    },
    PickerChange(e) {
      this.indexPicker = e.mp.detail.value
      this.objEdit.supplierName = this.array[e.mp.detail.value].supplierName
      this.objEdit.supplierId = this.array[e.mp.detail.value].supplierId
      this.getGoodsName(this.objEdit.supplierName)
    },
    PickerWarehouseChange(e) {
      this.indexWarePicker = e.mp.detail.value
      this.objEdit.warehouseName = this.arrayWarehouse[
        e.mp.detail.value
      ].warehouseName
      this.objEdit.warehouseId = this.arrayWarehouse[
        e.mp.detail.value
      ].warehouseId
    },
    // async getBelt() {
    //   const { rows } = await home.getBeltLevel({ dictType: "beltType" })
    //   this.arrayBelt = rows
    //   this.objEdit.beltType = this.arrayBelt[0].dictValue
    // },
    // async getLevel() {
    //   const { rows } = await home.getBeltLevel({ dictType: "goodsLevel" })
    //   this.arrayLevel = rows
    //   this.objEdit.goodsLevel = this.arrayLevel[0].dictValue
    // },
    PickerBeltChange(e) {
      this.indexBeltPicker = e.mp.detail.value
      this.beltType = this.arrayBelt[e.mp.detail.value].dictLabel
      this.objEdit.beltType = this.arrayBelt[e.mp.detail.value].dictValue
      if (this.objEdit.beltTypeName == '其它'||this.objEdit.beltTypeName=='其他') {
        this.beltTypeNameInputFlag = true
      } else {
        this.beltTypeNameInputFlag = false
      }
    },
    PickerLevelChange(e) {
      this.indexLevelPicker = e.mp.detail.value
      this.goodsLevel = this.arrayLevel[e.mp.detail.value].dictLabel
      this.objEdit.goodsLevel = this.arrayLevel[e.mp.detail.value].dictValue
    },
    async editBtn() {
      // this.objEdit.beginPicUrl = this.files
      // 确认提交，还要验收后照片
      const flag = {
        supplierId: this.local.supplier, //  供应商id
        supplierName: this.local.supplier,
        warehouseId: this.local.warehouseIn, // 仓库id
        warehouseName: this.local.warehouseIn,
        goodsName: this.local.goodsName, //    商品名称
        beltType: this.local.beltType, //   皮带类型
        goodsLevel: this.local.grade, //   等级
        sizeHeight: this.local.thickness, //   厚度
        sizeWidth: this.local.width, //   宽度
        sizeLong: this.local.length, //   长度
        weight: this.local.weight, //   净重
        // totalWeight: '', //  总重
        remark: this.local.remark, //  备注
        remark2: this.local.remark2, //  备注2
        beginPicUrl: this.local.photosBeforeAcceptance, // 验收前照片
        endPicUrl: this.local.photosAfterAcceptance, // 验收前照片
        weightBridgePier: this.local.weighbridgeTerminalNo,
        supplierInvoice: this.local.supplierInvoiceNumber,
        invoiceDate: this.local.invoiceDate
      }
      this.objEditNew = {
        invoiceDate: this.objEdit.invoiceDate,
        id: this.objEdit.id,
        supplierId: this.objEdit.supplierId, //  供应商id
        supplierName: this.objEdit.supplierName,
        warehouseId: this.objEdit.warehouseId, // 仓库id
        warehouseName: this.objEdit.warehouseName,
        goodsCode: this.objEdit.goodsCode,
        goodsName: this.objEdit.goodsName, //    商品名称
        beltType: this.objEdit.beltType, //   皮带类型
        beltTypeName: this.objEdit.beltTypeName, //   皮带类型
        goodsLevel: this.objEdit.goodsLevel, //   等级
        sizeHeight: this.objEdit.sizeHeight, //   厚度
        sizeWidth: this.objEdit.sizeWidth, //   宽度
        sizeLong: this.objEdit.sizeLong, //   长度
        weight: this.objEdit.weight, //   净重
        hub:  this.objEdit.hub == null ? '': this.objEdit.hub,
        steelReel: this.objEdit.steelReel == null ? '': this.objEdit.steelReel,
        hubName: this.objEdit.hubName,
        steelReelName: this.objEdit.steelReelName,
        frameType: this.objEdit.frameType == null ? '': this.objEdit.frameType,
        // totalWeight: this.objEdit.totalWeight, //  总重
        remark: this.objEdit.remark, //  备注
        remark2: this.objEdit.remark2, //  备注2
        beginPicUrl: this.filesStart.join(), // 验收前照片
        endPicUrl: this.filesEnd.join(), // 验收后前照片
        status: this.objEdit.status,
        weightBridgePier: this.objEdit.weightBridgePier,
        supplierInvoice: this.objEdit.supplierInvoice,
        type: 2  //1保存草稿 2提交
      }
      let map = ['frameType','remark','remark2','weightBridgePier','supplierInvoice','invoiceDate','hub','hubName','steelReel','steelReelName', 'beltTypeName']
      for (let i in this.objEditNew) {
        if (this.objEditNew[i] == "" && !map.includes(i)) {
          wx.showToast({
            title: `${flag[i]}${this.local.required}`,
            icon: "none",
            duration: 2000,
          })
          return
        }
      }
      const data = await home.editInStock(this.objEditNew)
      if (data.code !== 0) {
        wx.showToast({
          title: data.msg,
          duration: 2000,
          icon: "none",
        })
        // wx.navigateTo({
        //   url: '/packageA/pages/purchaseReceipt/index'
        // })
        return
      }
      wx.showLoading({
        title: `${this.local.jumping}`,
      })
      this.gotoPage("/packageA/pages/purchaseReceipt/index")
    },
    gotoPage: throttle(
      0,
      false,
      function(url) {
        this._func(url)
      },
      false
    ),
    _func(url) {
      wx.hideLoading()
      wx.navigateTo({
        url: url,
      })
    },
    pageReturn() {
      // 直接跳转到入库列表
      wx.navigateBack({
        // 返回
        delta: 3,
      })
      wx.showToast({
        title: "",
        icon: "none",
        duration: 2000,
      })
      // wx.setStorageSync('stockInObj', {})
    },
    changeLan(val, lang) {
      this.local = val
      this.lang = lang
    },
    async getWarehouseList() {
      const { rows } = await home.getWarehouseList()
      this.arrayWarehouse = rows
    },
    async getInStockListId() {
      const data = await home.getInStockListId({ id: this.id })
      this.objEdit = data
      if (this.objEdit.invoiceDate && this.objEdit.invoiceDate.length !== 0) {
        this.objEdit.invoiceDate = this.objEdit.invoiceDate.substring(0, 10)
      }
      this.objEdit.createTime = wx.$timeFormat(data.createTime,'time') //new Date(data.createTime).$format('dd/MM/yyyy hh:ss')
      this.titleBar = data.status == 'SAVE' ? false : true
      this.objEdit.endPicUrl =  data.endPicUrl == null ? [] : data.endPicUrl.split(",")
      this.filesEnd = this.objEdit.endPicUrl
      this.objEdit.beginPicUrl = data.beginPicUrl == null ? []: data.beginPicUrl.split(",")
      this.objEdit.beginPicUrl = this.objEdit.beginPicUrl
      this.filesStart = this.objEdit.beginPicUrl
      if (
        this.objEdit.supplierInvoice == "undefined" ||
        this.objEdit.supplierInvoice == undefined ||
        this.objEdit.supplierInvoice == null ||
        this.objEdit.supplierInvoice == "null"
      ) {
        this.objEdit.supplierInvoice = ""
      }
      if (
        this.objEdit.weightBridgePier == "undefined" ||
        this.objEdit.weightBridgePier == undefined ||
        this.objEdit.weightBridgePier == null ||
        this.objEdit.weightBridgePier == "null"
      ) {
        this.objEdit.weightBridgePier = ""
      }
      if (this.objEdit.remark == "null" || this.objEdit.remark == null) {
        this.objEdit.remark = ""
      }
      if (this.objEdit.remark2 == "null" || this.objEdit.remark2 == null) {
        this.objEdit.remark2 = ""
      }
      //设置等级、皮带类型
      this.goodsLevel = dictMatching(
        wx.getStorageSync("goodsLevel"),
        this.objEdit.goodsLevel
      )
      this.beltType = dictMatching(
        wx.getStorageSync("beltType"),
        this.objEdit.beltType
      )
      this.arrayLevel.map((item, index) => {
        if (item.dictValue == this.objEdit.goodsLevel) {
          this.indexLevelPicker = index
        }
      })
      this.arrayBelt.map((item, index) => {
        if (item.dictValue == this.objEdit.beltType) {
          this.indexBeltPicker = index
        }
     })

    //设置初始 框架类型
    // this.objEdit.frameType = this.objEdit.hub == null ? '2':'1'
    //  todo 删除
     this.frameTypeText = this.objEdit.frameType && dictMatching(wx.getStorageSync("frameType"),this.objEdit.frameType)
     this.arrayFrameType.map((item, index) => {
        if (item.dictValue == this.objEdit.frameType) {
          this.indexFrameTypePicker = index
        }
     })
     this.hubText = this.objEdit.hub && dictMatching(
        wx.getStorageSync("hubType"),
        this.objEdit.hub
      )
      this.steelReelText = dictMatching(
        wx.getStorageSync("steelReel"),
        this.objEdit.steelReel
      )
      this.arrayHub.map((item, index) => {
        if (item.dictValue == this.objEdit.hub) {
          this.indexHubPicker = index
        }
      })
      this.arraySteelReel.map((item, index) => {
        if (item.dictValue == this.objEdit.steelReel) {
          this.indexSteelReelPicker = index
        }
     })
    },
    resetData(){
      this.objEdit = {}
      this.indexFrameTypePicker = null
      this.indexHubPicker = 0
      this.indexSteelReelPicker = 0
      this.indexBeltPicker = 0
      this.indexLevelPicker = 0
      this.indexSymbolPicker = 0
      this.indexWarePicker = 0
      this.indexPicker = 0
    },
    routerToUrl(url) {
      wx.navigateTo({
        url,
      })
    },
    chooseImage() {
      var _this = this
      wx.chooseImage({
        sizeType: ["original", "compressed"], // 可以指定是原图还是压缩图，默认二者都有
        sourceType: ["album", "camera"], // 可以指定来源是相册还是相机，默认二者都有
        success: function(res) {
          // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
          // _this.filesStart = _this.filesStart.concat(res.tempFilePaths)
          res.tempFilePaths.map((item, i) => {
            wx.uploadFile({
              url: `${Shop.BASE_URL}applet/buy/storage/common/upload`,
              filePath: item, // chooseImage上传的图片
              name: "file", // 需要传给后台的图片字段名称
              formData: item, // 需要传给后台的其他表单数据
              header: {
                Authorization: wx.getStorageSync("token"),
              },
              success: res => {
                if (res.statusCode == 200) {
                  let { code, url, msg } = JSON.parse(res.data)
                  if (code == 0) {
                    _this.filesStart.push(url)
                  } else {
                    wx.showToast({
                      title: msg,
                      duration: 4000,
                      icon: "none",
                    })
                  }
                } else {
                  wx.showToast({
                    title: _this.local.uploadFail,
                    duration: 4000,
                    icon: "none",
                  })
                }
              },
            })
          })
        },
        fail: function() {},
        complete: function() {},
      })
      // _this.$set(_this.objEdit.beginPicUrl, 'beginPicUrl', _this.objEdit.beginPicUrl)
    },
    chooseImageEnd() {
      var _this = this
      // let center = []
      // center = _this.objEdit.endPicUrl
      wx.chooseImage({
        sizeType: ["original", "compressed"], // 可以指定是原图还是压缩图，默认二者都有
        sourceType: ["album", "camera"], // 可以指定来源是相册还是相机，默认二者都有
        success: function(res) {
          // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
          // _this.filesEnd = _this.filesEnd.concat(res.tempFilePaths)
          res.tempFilePaths.map((item, i) => {
            wx.uploadFile({
              url: `${Shop.BASE_URL}applet/buy/storage/common/upload`,
              filePath: item, // chooseImage上传的图片s
              name: "file", // 需要传给后台的图片字段名称
              formData: item, // 需要传给后台的其他表单数据
              header: {
                Authorization: wx.getStorageSync("token"),
              },
              success: res => {
                if (res.statusCode == 200) {
                  let { code, url, msg } = JSON.parse(res.data)
                  if (code == 0) {
                    _this.filesEnd.push(url)
                    // for (let h in _this.objEdit.endPicUrl) {
                    //   this.$set(_this.objEdit.endPicUrl, h, _this.objEdit.endPicUrl[h])
                    // }
                  } else {
                    wx.showToast({
                      title: msg,
                      duration: 4000,
                      icon: "none",
                    })
                  }
                } else {
                  wx.showToast({
                    title: _this.local.uploadFail,
                    duration: 4000,
                    icon: "none",
                  })
                }
              },
            })
          })
        },
        fail: function() {},
        complete: function() {},
      })
    },

    changeBuyArea(e){
      const {value} = e.target
      const {buyAreaName,buyAreaId} = this.buyAreaList[value]
      this.buyAreaPickerIndex = value
      this.objEdit.buyAreaName = buyAreaName
      this.objEdit.buyAreaId = buyAreaId
    },
    predivImage(e) {
      previewImage(e)
      // const that = this
      // let filesStartArr = []
      // that.filesStart.map(item => {
      //   filesStartArr.push(`${Shop.IMG_URL}${item}`)
      // })
      // wx.previewImage({
      //   current: `${Shop.IMG_URL}${e.currentTarget.id}`, // 当前显示图片的http链接
      //   urls: filesStartArr, // 需要预览的图片http链接列表
      //})
    },
    predivImageEnd(e) {
      previewImage(e)
      // const that = this
      // let filesStartArr = []
      // that.filesEnd.map(item => {
      //   filesStartArr.push(`${Shop.IMG_URL}${item}`)
      // })
      // wx.previewImage({
      //   current: e.currentTarget.id, // 当前显示图片的http链接
      //   urls: filesStartArr, // 需要预览的图片http链接列表
      // })
    },
  },
  data() {
    return {
      beltTypeNameInputFlag: false,
      lang: wx.getStorageSync("lang"),
      titleBar: false,
      Shop: Shop.BASE_URL,
      beltType: '请选择',
      goodsLevel: '请选择',
      hubText: '请选择',
      steelReelText:'请选择',
      frameTypeText: '请选择',
      local: wx.getStorageSync("local"),
      pdt: 66,
      width: "100px",
      objEdit: {
        invoiceDate: '',
        weightBridgePier: "",
        supplierInvoice: "",
        supplierId: 0, //  供应商id
        supplierName: "",
        warehouseId: 0, // 仓库id
        warehouseName: "",
        goodsName: "", //    商品名称
        beltType: "", //   皮带类型
        goodsLevel: "", //   等级
        sizeHeight: "", //   厚度
        sizeWidth: "", //   宽度
        sizeLong: "", //   长度
        weight: "", //   净重
        frameType: "",
        // totalWeight: '', //  总重
        remark: "", //  备注
        remark2: "", //  备注2
        beginPicUrl: [], // 验收前照片
        endPicUrl: [],
      },
      indexPicker: 1,
      indexSymbolPicker: 0,
      indexBeltPicker: 1,
      indexLevelPicker: 1,
      indexWarePicker: 1,
      indexHubPicker: 0,
      indexSteelReelPicker: 0,
      indexFrameTypePicker: null,
      arraySymbol: ['>=', '<='],
      array: ["美国", "中国", "阿拉伯", "非洲"],
      arrayWarehouse: ["1号仓库", "2号仓库", "3号仓库", "4号仓库"],
      arrayLevel: wx.getStorageSync('goodsLevel') || [],
      arrayBelt: wx.getStorageSync('beltType') || [],
      arraySteelReel: wx.getStorageSync('steelReel') || [],
      arrayHub: wx.getStorageSync('hubType') || [],
      arrayFrameType: wx.getStorageSync('frameType') || [],
      files: [],
      filesStart: [],
      filesEnd: [],
      logs: [],
      fileList: [],
      buyAreaList:[],
      buyAreaPickerIndex:0
    }
  },
  created() {},
}
</script>

<style scoped lang="scss">
@import 'index';
.log-list {
  display: flex;
  flex-direction: column;
  padding: 40rpx;
}

.log-item {
  margin: 10rpx;
}
</style>
